package logic

import (
	"context"
	"user-login1/userrpc/userrpc"

	"user-login1/api/internal/svc"
	"user-login1/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPerfectLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPerfectLogic {
	return &UserPerfectLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPerfectLogic) UserPerfect(req *types.UserPerfectRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	perfect, err := l.svcCtx.UserRpc.UserPerfect(l.ctx, &userrpc.UserPerfectRequest{
		UserId:     req.Userid,
		HeadImage:  req.Headimage,
		NickName:   req.Nickname,
		Address:    req.Address,
		WechatCode: req.WechatCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "完善个人信息成功",
		Code:    200,
		Data:    perfect,
	}, nil
}
